// pages/wuliuXinxi/wuliuXinxi.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    wuliuList: [
      { name: '邮政快递包裹', flags: false, code: 'YZPY' },
      { name: 'EMS', flags: false, code: 'EMS' },
      { name: '天天快递', flags: false, code: 'HHTT' },
      { name: '京东快递', flags: false, code: 'JD' },
      { name: '优速快递', flags: false, code: 'UC' },
      { name: '德邦快递', flags: false, code: 'DBL' },
      { name: '宅急送', flags: false, code: 'ZJS' },
      { name: 'TNT快递', flags: false, code: 'TNT' },
      { name: 'UPS', flags: false, code: 'UPS' },
      { name: 'DHL', flags: false, code: 'DHL' },
      { name: 'FEDEX联邦(国内件）', flags: false, code: 'FEDEX' },
      { name: 'FEDEX联邦(国际件）', flags: false, code: 'FEDEX_GJ' },
      { name: '厂家自配送', flags: false, code: '0' }
    ],
    name:'',
    wuliuinfo:''
  },
  wuliuinfo(){
    let that = this
    wx.request({
      url: app.globalData.myurl,
      data: {
        cmd: "getExpressInfo",
        shopId: wx.getStorageSync('shopId'),
        userId: wx.getStorageSync('userId'),
        orderId: that.data.id
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        if (res.data.zjstate == 1) {
          setTimeout(function () {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function () {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮false去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        console.log(res)
        if (res.data.result == 1) {
          setTimeout(function () {
            wx.hideLoading()
          }, 0)
          setTimeout(function () {
            wx.showToast({
              title: res.data.resultNote,
              icon: 'none',
              duration: 1500
            })
          }, 0)
        } else {
          let name = ''
          for(let i in that.data.wuliuList){
            if (that.data.wuliuList[i].code == res.data.bean.express.shipperCode){
              name = that.data.wuliuList[i].name
            }
          }
          that.setData({
            wuliuinfo: res.data.bean,
            name: name
          })
          setTimeout(function () {
            wx.hideLoading()
          }, 0)
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      id: options.id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    setTimeout(function () {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    that.wuliuinfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})